package com.portal.cwegportal.controller;
import com.appcenter.jz.Logger.BusinessLogger;
import com.appcenter.jz.Logger.LoggerGenre;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;

import com.portal.cwegportal.input.functionmap.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("api/services/portal/functionmap")
@Api(description = "功能地图API")
public class FunctionMapController {
    @Autowired
    com.portal.cwegportal.service.FunctionMapService functionMapService;

    @ApiOperation(value = "创建功能地图", notes = "创建功能地图", produces = "application/json")
    @PostMapping("/createFunctionMap")
    public ResponseEntity<JsonResult> createFunctionMap(@RequestBody CreateFunctionMapInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"创建功能地图",input);
        JsonResult r = new JsonResult();

        try {
            r.setResult(functionMapService.createFunctionMap(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "删除功能地图", notes = "删除功能地图",produces = "application/json")
    @PostMapping("/deleteFunctionMap")
    public ResponseEntity<JsonResult> deleteFunctionMap(@RequestBody DeleteFunctionMapInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"删除功能地图",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(functionMapService.deleteFunctionMap(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }


    @ApiOperation(value = "修改功能地图", notes = "修改功能地图",produces = "application/json")
    @PostMapping("/editFunctionMap")
    public ResponseEntity<JsonResult> editFunctionMap(@RequestBody EditFunctionMapInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"修改功能地图",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(functionMapService.editFunctionMap(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "搜索功能地图", notes = "搜索功能地图",produces = "application/json")
    @PostMapping("/getFunctionMap")
    public ResponseEntity<JsonResult> getFunctionMap(@RequestBody GetFunctionMapsInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        BusinessLogger.Info( LoggerGenre.Add,"搜索功能地图",input);
        JsonResult r = new JsonResult();

        try {
            r.setResult(functionMapService.getFunctionMaps(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }

        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "加载功能地图信息", notes = "加载功能地图信息",produces = "application/json")
    @PostMapping("/pageLoad")
    public ResponseEntity<JsonResult> pageLoad(@RequestBody PageLoadInput input) throws Exception {
        BusinessLogger.Info( LoggerGenre.Add,"加载功能地图信息",input);
        JsonResult r = new JsonResult();
        try {
            r.setResult(functionMapService.pageLoad(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
}
